package io.github.wanggit.antrpc.boot;

import io.github.wanggit.antrpc.client.zk.lb.RoundLoadBalancer;
import io.github.wanggit.antrpc.commons.config.*;
import io.github.wanggit.antrpc.commons.constants.ConstantValues;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.util.Map;

@Data
@ConfigurationProperties(prefix = ConstantValues.ANTRPC_CONFIG_PREFIX)
class RpcProperties {

    /** Zookeeper默认地址，多个使用逗号间隔 */
    private String zkServers = "localhost:2181";

    private Integer port = 6060;

    private String loadBalancer = RoundLoadBalancer.class.getName();

    /** 是否做为RPC的服务端启动 */
    private boolean startServer = true;

    /** 有多个网卡时，对外暴露的IP地址。会使用此地址向Zookeeper注册 */
    private String exposedIp;

    /** 可以添加配置中心的多个共享空间，使用逗号间隔 */
    private String configSharedSpaces;

    /** 指明使用配置中心的环境，默认不分环境，就是default */
    private String configEnv;

    /** 全局接口熔断设置 */
    @NestedConfigurationProperty private CircuitBreakerConfig circuitBreakers;

    /** 服务之间的连接熔断设置 */
    @NestedConfigurationProperty private CircuitBreakerConfig connectionBreakerConfig;

    @NestedConfigurationProperty private CallLogReporterConfig callLogReporterConfig;

    @NestedConfigurationProperty private RpcClientsConfig rpcClientsConfig;

    @NestedConfigurationProperty private CodecConfig codecConfig;

    @NestedConfigurationProperty private TelnetConfig telnetConfig;

    @NestedConfigurationProperty private SerializeConfig serializeConfig;

    /** 开发阶段的接口直连 direct rpc host -> ip:port */
    private Map<String, String> directHosts;

    /** 接口级别的熔断设置 */
    private Map<String, CircuitBreakerConfig> interfaceCircuitBreaker;
}
